package com.lfy.auth.controller;

import com.lfy.auth.service.UserService;
import com.lfy.common.enums.BaseEnum;
import com.lfy.common.result.R;
import com.lfy.commons.anno.limit.CurrentLimit;
import com.lfy.commons.anno.user.NoNeedLogin;
import com.lfy.commons.strategy.LimitStrategyEnum;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@Controller
public class AcController {
    @Resource
    private UserService userService;
    @GetMapping("/activation")
    @CurrentLimit(time = 1,once = 10,nuit = TimeUnit.DAYS,strategy = LimitStrategyEnum.Ip)
    @NoNeedLogin
    public String ac(@RequestParam("code") String code){
        R r = this.userService.activation(code);
        if(r.getCode().equals(BaseEnum.authEnum.ACTIVATION_SUCCESS.getCode())){
            //激活成功，初始化用户信息

            return "redirect:http://127.0.0.1:5173/ac/1";
        }else {
            return "redirect:http://127.0.0.1:5173/ac/2";
        }
    }
}
